package edu.jd.movieplatform.c_admin.movie;

import edu.jd.movieplatform.common.CommonService;
import edu.jd.movieplatform.common.CurrentManager;
import edu.jd.movieplatform.common.MTokenUtils;
import edu.jd.movieplatform.common.Result;
import org.apache.catalina.valves.rewrite.RewriteCond;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/c_admin/movie")
public class ScreenAPI {
    @Resource
    private CommonService commonService;
    @Resource
    private ScreenService service;

    @GetMapping("")
    public Result screenList(ScreenDto dto){
        Map<String,Object> page = service.getScreenList(dto);
        return Result.success(page);
    }

    @PostMapping("")
    public Result screenAdd(@RequestBody AddDto dto){
        service.addScreen(dto);
        return Result.success();
    }

    @PostMapping("/updScreen")
    public Result screenUpd(@RequestBody UpdDto dto){
        service.updScreen(dto);
        return Result.success();
    }
    @GetMapping("/getCinemaHallIdByName")
    public Result CinemaHallIdList(AddDto dto){
        String name=dto.getCnm_name();
        List<Integer> cinemaIdList= service.getCinemaIdList(name);
        return Result.success(cinemaIdList);
    }

    @GetMapping("/currentManager")
    public Result currentManager(@RequestHeader("Token") String token){
        CurrentManager currentManager = MTokenUtils.getUserInfo(token,commonService);
        return Result.success(currentManager);
    }

    @DeleteMapping("/{id}")
    public Result delScreen(@PathVariable Integer id){
        service.delScreen(id);
        return Result.success();
    }
}
